package com.run.motion.controller;

import com.run.motion.entity.FoodDetailType;
import com.run.motion.service.IFoodDetailTypeService;
import com.run.motion.util.page.AjaxResult;
import com.run.motion.util.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;

/**
 * @author tyx-qchk
 * @date 2022/12/5 14:10
 */
@Api(tags = "食物二级分类")
@RestController
@RequestMapping("/food/detail/type")
public class FoodDetailTypeController extends BaseController{
    @Autowired
    IFoodDetailTypeService foodDetailTypeService;
    /**
     * 查询食物二级分类列表
     */
    @ApiOperation(value = "查询食物二级分类列表")
    @GetMapping("/list")
    public TableDataInfo list()
    {
        startPage();
        List<FoodDetailType> list = foodDetailTypeService.selectFoodDetailTypeList();
        return getDataTable(list);
    }

    /**
     * 根据一级分类id查询食物二级分类列表
     */
    @ApiOperation(value = "根据一级分类id查询食物二级分类列表")
    @GetMapping("/list/{foodTypeId}")
    public TableDataInfo byFoodTypeIdList(@PathVariable("foodTypeId") String foodTypeId)
    {
        startPage();
        List<FoodDetailType> list = foodDetailTypeService.selectFoodDetailTypeListByFoodTypeId(foodTypeId);
        return getDataTable(list);
    }



    /**
     * 获取食物二级分类详细信息
     */
    @ApiOperation(value = "获取食物二级分类详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(foodDetailTypeService.selectFoodDetailTypeById(id));
    }

    /**
     * 新增食物二级分类
     */
    @ApiOperation(value = "新增食物二级分类")
    @PostMapping
    public AjaxResult add(@RequestBody FoodDetailType foodDetailType)
    {
//        生成uuid
        String id = String.valueOf(UUID.randomUUID());
        foodDetailType.setId(id);
        return toAjax(foodDetailTypeService.insertFoodDetailType(foodDetailType));
    }

    /**
     * 修改食物二级分类
     */
    @ApiOperation(value = "修改食物二级分类")
    @PutMapping
    public AjaxResult edit(@RequestBody FoodDetailType foodDetailType)
    {
        return toAjax(foodDetailTypeService.updateFoodDetailType(foodDetailType));
    }

    /**
     * 删除食物二级分类
     */
    @ApiOperation(value = "删除食物二级分类")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(foodDetailTypeService.deleteFoodDetailTypeByIds(ids));
    }
}
